import axios from 'axios'

// 本地测试环境，后端API地址
const baseURL = 'http://localhost:8000/api/v1'
// 开发环境，后端API地址
// const baseURL = 'http://192.168.1.100:8000/api/v1'
const service = axios.create({
  baseURL,
  timeout: 5000
})
// 请求拦截器，自动加token
service.interceptors.request.use(config => {
  const token = localStorage.getItem('token')
  if (token) {
    config.headers['Authorization'] = 'Bearer ' + token
  }
  return config
})

export { baseURL }
export default service
